// components/custom-tab-bar/index.js
Component({
  /**
   * 组件的初始数据
   */
  data: {
    selected: 0,
    color: "#6E758F",
    selectedColor: "#306FDB",
    list: [{
        "pagePath": "/pages/index/index",
        "text": "首页",
        "iconPath": "/assets/images/tabbar/home-normal.png",
        "selectedIconPath": "/assets/images/tabbar/home-selected.png"
      },
      {
        "pagePath": "/pages/mine/mine",
        "text": "我的",
        "iconPath": "/assets/images/tabbar/mine-normal.png",
        "selectedIconPath": "/assets/images/tabbar/mine-selected.png"
      }
    ]
  },

  /**
   * 组件的方法列表
   */
  methods: {
    switchTab(e) {
      const data = e.currentTarget.dataset;
      const url = data.path;

      wx.switchTab({
        url,
        success: () => {
          let index = 0;
          for (let i = 0; i < this.data.list.length; i++) {
            const item = this.data.list[i];
            if (item.pagePath == url) {
              index = i;
              break;
            }
          }
          this.setData({
            selected: index,
          });
        }
      });
    }
  },
})